//
//  YLJBrightnessViewController.m
//  ACE
//
//  Created by Mickey Yin on 2022/6/18.
//

#import "YLJBrightnessViewController.h"
#import "JCBrightness.h"

@interface YLJBrightnessViewController ()

@end

@implementation YLJBrightnessViewController

//页面出现时的方法
- (void)viewDidAppear:(BOOL)animated
{
    //设置亮度   0.8的亮度差不多了
    [JCBrightness graduallySetBrightness:1];
}

//页面消失时的方法
- (void)viewDidDisappear:(BOOL)animated
{
    // 恢复亮度
    [JCBrightness graduallyResumeBrightness];
}


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
   
    self.view.backgroundColor = UIColor.blueColor;
    self.navigationItem.title = @"亮度";
    
    [self addNSNotification];
    
    //保存亮度
    [JCBrightness saveDefaultBrightness];
}


#pragma mark --添加通知
-(void)addNSNotification{
    
//    UIKIT_EXTERN NSString *const UIApplicationDidBecomeActiveNotification;     //程序变成激活状态
//    UIKIT_EXTERN NSString *const UIApplicationWillResignActiveNotification;    //程序将失去激活状态
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(DidBecomeActive) name:UIApplicationDidBecomeActiveNotification object:nil];

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(willResignActive) name:UIApplicationWillResignActiveNotification object:nil];
}

//成为激活状态，调高亮度
-(void)DidBecomeActive{
    [JCBrightness graduallySetBrightness:1];
}

//失去激活状态，快速恢复之前的亮度
-(void)willResignActive{
    [JCBrightness fastResumeBrightness];
    NSLog(@"mmmmmmm---777--退到后台");
}


#pragma mark 移除本地所有通知
-(void)removeNotification{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}


@end
